# -*- coding: utf-8 -*-
__doc__ = '我的草稿页面'

from selenium.webdriver.common.by import By

from PageClass.basePage import BasePage
from Util import logger, ZTCCLOUDError


class EcsUserDraftPage(BasePage):
    # 单据编号
    _boeNo = (By.ID, 'undefined_boeNo')

    def getBoeNo(self):
        return self._boeNo

    def input_boeNo(self, text):
        self.send_text(text, *self._boeNo)
        logger.info(f"输入查询的单据编号为：{text}")

    # 查询
    def click_boeNoSelectButton(self):
        self.click_button('查询')
        logger.info("点击查询按钮")

    # 查询结果
    _boeNoSelectResult = (By.XPATH, '//*[@id="app"]//table/tbody/tr/td[3]')

    def selectResultIsOrNot(self, boeNum):
        if self.get_elementText(*self._boeNoSelectResult) == boeNum:
            logger.info("Success ， 查询出对应结果")
            return True
        else:
            logger.info("Fail ， 没有查询出对应结果")
            return False

    def __checkBoeSelect(self, *loc) -> bool:
        return 'is-checked' in self.find_elements(*loc)[-1].get_attribute('class')

    # 勾选单据
    _boeLoc = (By.XPATH, '//*[@id="app"]//table/tbody/tr[1]')

    def selectBoe(self):
        waitCheckLoc = (By.XPATH, '//div[@class="el-table__fixed-body-wrapper"][1]//tr/td/div/label')
        flag = False
        n = 10
        while n > 0:
            if not self.__checkBoeSelect(*waitCheckLoc):
                self.click(*self._boeLoc)
            else:
                logger.info('勾选单据')
                flag = True
                break
            n -= 1
        if not flag:
            raise ZTCCLOUDError('勾选单据失败')

    # 点击删除按钮
    def click_deleteButton(self):
        self.click_button('删除')
        logger.info('点击删除按钮')

    # 点击确认
    def click_boeBusinessTipConfirm(self):
        self.click_button('确认')
        logger.info('点击确认按钮')
